<?php
	include("includes/secure.php");
	include("includes/config.php");
	include("includes/class/afp.class.php");
	
	$afp = new Afp(); 
	$afp_code	= $_GET['afp_code'];
	$msg_info = $msg_alert = $msg_error = false;
	$_SESSION['msg_cool'] = '';
	$show_msg = 0;
	
	$data = $afp->getAfpData($afp_code);
	
	
	if(isset($_POST['edit']) && $_POST['edit'] == 1){
		$new_data->afp_code			= $_POST['afp_code'];
		$new_data->afp_name 		= trim(mysql_real_escape_string($_POST['afp_name']));
		$new_data->afp_porc	        =  $_POST['afp_porc'];
		$new_data->afp_description	= trim(mysql_real_escape_string($_POST['afp_description']));
		
		if ( $afp->updateAfp($new_data) ){
			$_SESSION["msg_cool"] .= 'la afp fue actualizada..<br />';
					
				echo "<script> window.location.href='listafp.php?show_msg=3'</script>";
		}
		else{
			$msg_error = true;
			$_SESSION["msg_cool"] .= 'No se pudo actualizar la afp...<br />';
		}		
	}
	
	if ( $msg_error )
		$show_msg = 1;
	elseif ( $msg_alert )
		$show_msg = 2;
	elseif ( $msg_info )
		$show_msg = 3;
?>